<?php
ob_implicit_flush(true);
ini_set("display_errors", 1); 
error_reporting(E_ALL);

define( 'DS', DIRECTORY_SEPARATOR );
define( 'ROOT', dirname(__FILE__) );
define( 'APP', ROOT . DS . 'app' . DS );
define( 'LIBS', ROOT . DS . 'lib' . DS );
define( 'CONFIGS', APP . 'config' . DS );
define( 'CONTROLLERS', APP . 'controllers' . DS );
define( 'VIEWS', APP . 'views' . DS );

require_once LIBS . 'basics.php';

uses('Object', 'Inflector', 'Set', 'App', 'View', 'Controller', 'Dialog');

if(!App::import('Controller', 'App')) {
	App::import('Core', 'AppController');
}

if(isset($argv[1])) {
	$controllerName = $argv[1];
} else {
	$controllerName = 'Test';
}

App::import('Controller', $controllerName);
$controllerName = $controllerName . 'Controller';

if(!class_exists($controllerName)) {
	die('Controller does not exist');
}

$controller =& new $controllerName;

$controller->beforeStart();
$controller->start();
$controller->afterStart();        

if($controller->autoRender) {
 	$controller->beforeRender();
	$controller->render();   
}               

$controller->end();

?>